/*!
 @header UserInfoViewController.m
 @abstract
 @author 周益
 @version 1.00 2013/02/21 Creation
 Copyright (c) 2013年 mypocketbaby. All rights reserved.
 */

//  -业务逻辑细节说明-
//
//  @abstract       此VC并无业务逻辑，基于tableVC，旨在显示用户的个人信息和提供可修改功能。
//                      

//  @discussion     

//  @notes          点击头像栏时，要求可以让用户选择拍照和相册选取。用户在完成拍照或者相册选取后，VC会对此照片按照预先商定好的尺寸裁剪图片。完成裁剪后压缩封装（压缩比率和大小也是预先商定好的）准备向服务器请求个人信息的修改。
//                  点击地区栏时，弹出自定义的pickerview，要求是最多3级城市。


//  -类修改日志-
//  修改人   修改时间   针对版本   修改描述

#import "UserInfoViewController.h"
#import "Helper.h"
#import "Config.h"
#import "QuartzCore/QuartzCore.h"
#import "Collage.h"
#import "CollageManager.h"
#import "ProvincePickerViewController.h"

@interface UserInfoViewController ()

@end

@implementation UserInfoViewController
@synthesize delegate = _delegate;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
        [self userInfoRequest];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    //返回
    UIButton *backButton = [Helper buttonWithStyle:ButtonStyleNavigationReturn];
    [backButton addTarget:self action:@selector(backButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    //完成
    UIButton *finishButton = [Helper buttonWithStyle:ButtonStyleNavigationDone];
    [finishButton addTarget:self action:@selector(finishButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:finishButton];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
    
    //设置背景
    self.view.backgroundColor = _SYS_COLOR_BACKGROUND;
    self.tableView.backgroundView = nil;
    
    //设置不可滚动
    self.tableView.scrollEnabled = NO;
    
    _sexArray = [[NSArray alloc] initWithObjects:@"女", @"男", nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    // Return the number of sections.
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    // Return the number of rows in the section.
    if (section == 0) {
        return 1;
    }
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    // Configure the cell...
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        
        //信息类型
        UILabel *infoTypeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 10.5f, 70.0f, 23.0f)];
        infoTypeLabel.font = _SYS_FONT_006;
        infoTypeLabel.backgroundColor = [UIColor clearColor];
        [cell.contentView addSubview:infoTypeLabel];
        
        //信息内容
        //如果section为0，则显示为头像，否则为其它基本信息
        if (indexPath.section == 0) {
            
            _avatarImageView = [[UIImageView alloc] initWithFrame:CGRectMake(320.0f - 40.0f - 45.0f, 4.5f, 35.0f, 35.0f)];
            _avatarImageView.backgroundColor = [UIColor clearColor];
            [cell.contentView addSubview:_avatarImageView];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            
        }else{
            UILabel *infoDetailLabel = [[UILabel alloc] initWithFrame:CGRectMake(90.0f, 10.5f, 190.0f, 23.0f)];
            infoDetailLabel.textColor = _SYS_COLOR_002;
            infoDetailLabel.font = _SYS_FONT_006;
            infoDetailLabel.backgroundColor = [UIColor clearColor];
            [cell.contentView addSubview:infoDetailLabel];
            if (indexPath.row == 5) {
                infoDetailLabel.lineBreakMode = UILineBreakModeWordWrap;
                infoDetailLabel.numberOfLines = 0;
            }
        }
    }
    //获得cell的子view
    NSArray *cellSubviews = [cell.contentView subviews];
    
    //信息类型
    UILabel *infoTypeLabel = [cellSubviews objectAtIndex:0];
    
    
    //渲染cell
    if (indexPath.section == 0) {
        
        infoTypeLabel.text = _L(@"title_42");   //头像
        
        
        //头像
        _avatarImageView = [cellSubviews objectAtIndex:1];
        
        if ([[_userInfoDataSource valueForKey:@"previewAvatar"] isKindOfClass:[NSString class]]) {
            _avatarImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[_userInfoDataSource valueForKey:@"previewAvatar"]]]];
        }
        
        
    }else{
        
        //信息内容
        UILabel *infoDetailLabel = [cellSubviews objectAtIndex:1];

        switch (indexPath.row) {
            case 0:
            {
                infoTypeLabel.text = _L(@"title_43");   //姓名
                
                infoDetailLabel.text = [_userInfoDataSource objectForKey:@"realName"];
            }
                break;
            case 1:
                infoTypeLabel.text = _L(@"title_37");   //性别
                infoDetailLabel.text = [[_userInfoDataSource objectForKey:@"sex"] intValue] == 1? _L(@"title_44") : _L(@"title_45");
                break;
            case 2:
                infoTypeLabel.text = _L(@"title_46");
                infoDetailLabel.text = [_userInfoDataSource objectForKey:@"birthday"];
                break;
            case 3:
            {
                infoTypeLabel.text = _L(@"title_47");
                
                if ([[_userInfoDataSource objectForKey:@"location"] length] == 0) {
                    
                    infoDetailLabel.text = [[_userInfoDataSource objectForKey:@"school"] componentsSeparatedByString:@" "][0];
                }
                else {
                    infoDetailLabel.text = [_userInfoDataSource objectForKey:@"location"];
                    
                }
                
            }
                break;
            case 4:
            {
                
                infoTypeLabel.text = _L(@"vc_title_111");
                infoDetailLabel.text = [_userInfoDataSource objectForKey:@"school"];
                
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                
            }
                break;
            case 5:
            {
                infoTypeLabel.text = _L(@"vc_title_054");
                
                infoDetailLabel.text = [_userInfoDataSource objectForKey:@"signature"];
                
                //根据个性签名的字数设置label的高
                CGSize size = [infoDetailLabel.text sizeWithFont:_SYS_FONT_007 constrainedToSize:CGSizeMake(200.0f, 100.0f) lineBreakMode:UILineBreakModeWordWrap];
                
                infoDetailLabel.frame = CGRectMake(90.0f, infoTypeLabel.frame.origin.y, 200.0f, size.height);
            }
            default:
                break;
        }
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 5) {
        return 100.0f;
    }
    return 44.0f;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        
        UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@""
                                                            delegate:self
                                                            cancelButtonTitle:_L(@"btn_no_01")
                                                            destructiveButtonTitle:nil
                                                            otherButtonTitles:_L(@"btn_photo_01"), _L(@"btn_photo_02"), nil];
        
        [actionSheet showInView:self.view];
    }else{
        
        //点击后删除之前的PickerView
        for (UIView *view in self.view.subviews) {
            if ([view isKindOfClass:[UICustomPickerView class]]) {
                [view removeFromSuperview];
            }
        }
        
        if (indexPath.row == 0) {
            //获得姓名cell的label
            UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:indexPath];
            
            UILabel *infoDetailLabel = [[selectedCell.contentView subviews] objectAtIndex:1];
            
            //点击了修改姓名栏,type=0,告诉InfoPickerViewController显示修改姓名的view
            InfoPickerViewController *infoPickerVC = [[InfoPickerViewController alloc] initWithContent:infoDetailLabel.text AndType:0];
            
            infoPickerVC.delegate = self;
            [infoPickerVC.navigationItem setTitle:_L(@"vc_title_053")];   //编辑姓名
            
            UINavigationController *infoPickerNC = [[UINavigationController alloc] initWithRootViewController:infoPickerVC];

            [Helper navigationControllerCommonStyle:infoPickerNC];
            
            [self.navigationController presentModalViewController:infoPickerNC animated:YES];
            
        //性别栏被点击
        }else if (indexPath.row == 1){
            
            _customPickerView = [[UICustomPickerView alloc] initWithFrame:CGRectMake(0,_SYS_FRAME_HEIGHT - 260-44, 320, 260)];
            _customPickerView.delegate = self;
            _customPickerView.dataSource = self;
            
            [self.view addSubview:_customPickerView];
            
            
            [_customPickerView pickerShow:UICustomPickerViewNormalType];
            
            [_customPickerView selectRow:[_userInfoDataSource[@"sex"] integerValue] inComponent:0 animated:NO];
            
        }else if (indexPath.row == 2){
            
            _customPickerView = [[UICustomPickerView alloc] initWithFrame:CGRectMake(0,_SYS_FRAME_HEIGHT - 260-44, 320, 260)];
            _customPickerView.delegate = self;
            
            //取到当前生日
            NSString *birthday = [_userInfoDataSource objectForKey:@"birthday"];
            
            //实例化一个NSDateFormatter对象
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
            //设定时间格式,这里可以设置成自己需要的格式
            [dateFormatter setDateFormat:@"yyyy-MM-dd"];
            
            //将日期定格在用户已选的日期上
            _customPickerView.currentDate = [dateFormatter dateFromString:birthday];
            
            
            [self.view addSubview:_customPickerView];
            [_customPickerView pickerShow:UICustomPickerViewDateType];
            
            
        }else if(indexPath.row == 3){
            
            _customPickerView = [[UICustomPickerView alloc] initWithFrame:CGRectMake(0,_SYS_FRAME_HEIGHT - 260-44, 320, 260)];
            _customPickerView.delegate = self;
            _customPickerView.location = [_userInfoDataSource objectForKey:@"location"];
            _customPickerView.hzAreaPickerStyle = HZAreaPickerWithStateAndCityAndDistrict;
            _customPickerView.areaPickerOption = HZAreaPickerInitNormalOption;
            [self.view addSubview:_customPickerView];
            
            [_customPickerView pickerShow:UICustomPickerViewAreaType];
            
        }else if (indexPath.row == 4){
            
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fillCollage:) name:@"fill_collage" object:nil];
            
            ProvincePickerViewController *provincePickerVC = [[ProvincePickerViewController alloc] initWithStyle:UITableViewStyleGrouped];
            
            //获得姓名cell的label
            UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:indexPath];
            
            UILabel *infoDetailLabel = [[selectedCell.contentView subviews] objectAtIndex:1];
            
            if ([[infoDetailLabel text] length] != 0 &&
                [[[infoDetailLabel text] componentsSeparatedByString:@" "] count] > 1
                ) {
                provincePickerVC.selectedCollageName = [[infoDetailLabel text] componentsSeparatedByString:@" "][1];
            }
            
            UINavigationController *provincePickerNC = [[UINavigationController alloc] initWithRootViewController:provincePickerVC];
            [Helper navigationControllerCommonStyle:provincePickerNC];
            [self.navigationController presentModalViewController:provincePickerNC animated:YES];
            
            
            //个性签名栏被点击
        }else if (indexPath.row == 5){
            //获得个性签名cell的label
            UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:indexPath];
            
            UILabel *infoDetailLabel = [[selectedCell.contentView subviews] objectAtIndex:1];
            
            
            //点击了修改姓名栏,type=1,告诉InfoPickerViewController显示修改个性签名的view
            InfoPickerViewController *infoPickerVC = [[InfoPickerViewController alloc] initWithContent:infoDetailLabel.text AndType:1];
            
            infoPickerVC.delegate = self;
            [infoPickerVC.navigationItem setTitle:_L(@"vc_title_054")];
            
            UINavigationController *infoPickerNC = [[UINavigationController alloc] initWithRootViewController:infoPickerVC];
            
            [Helper navigationControllerCommonStyle:infoPickerNC];
            
            [self.navigationController presentModalViewController:infoPickerNC animated:YES];
        }
    }
}

#pragma mark - 自定义事件

/*!
 @abstract 返回按钮事件
 */
- (void)backButtonEvent:(id)sender
{
    if ([_userInfoDataSource[@"previewAvatar"] isEqual:_primeDataSource[@"previewAvatar"]] &&
        [_userInfoDataSource[@"realName"] isEqualToString:_primeDataSource[@"realName"]] &&
        [_userInfoDataSource[@"sex"] intValue] == [_primeDataSource[@"sex"] intValue] &&
        [_userInfoDataSource[@"birthday"] isEqualToString:_primeDataSource[@"birthday"]] &&
        [_userInfoDataSource[@"school"] isEqualToString:_primeDataSource[@"school"]] &&
        [_userInfoDataSource[@"location"] isEqualToString:_primeDataSource[@"location"]] &&
        [_userInfoDataSource[@"signature"] isEqualToString:_primeDataSource[@"signature"]])
    {
        
        [self.navigationController popViewControllerAnimated:YES];
    }
    else {
        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil message:_L(@"alert_97") delegate:self cancelButtonTitle:_L(@"btn_no_01") otherButtonTitles:_L(@"btn_yes_01"), nil];
        [alertView show];
    }
}

/*!
 @abstract 完成按钮事件
 向服务器请求修改用户个人信息
 成功的代理方法为finishRequestSuccess:
 */
- (void)finishButtonEvent:(id)sender
{
    JSONRequest* request = [[JSONRequest alloc] initWithURLString:_JSON_URL_U_CHANGE_USERINFO];
    request.delegate = self;
    request.hudOn = true;
    request.hudTitle = _L(@"title_loading_01");
    request.requestMode = RequestModeMultiPart;
    [request setSuccessSelector:@selector(finishRequestSuccess:)];

    //姓名
    NSString *realName = _userInfoDataSource[@"realName"];
    
    if (realName != nil && ![realName isEqualToString:@""]) {

        [request setValue:realName forParameter:@"realName"];
    }
    
    //性别
    NSInteger sex = [_userInfoDataSource[@"sex"] integerValue];
    NSString *gender = sex == 1 ? @"true" : @"false";
    [request setValue:gender forParameter:@"sex"];
    
    //头像
    if ([_userInfoDataSource[@"previewAvatar"] isKindOfClass:[NSData class]]) {
        
        [request setValue:_userInfoDataSource[@"previewAvatar"] forParameter:@"avatr"];
    }
    
    //生日
    NSString *birthday = _userInfoDataSource[@"birthday"];
    
    if (birthday != nil && ![birthday isEqualToString:@""]) {

        [request setValue:birthday forParameter:@"birthday"];
    }
    
    //地区
    NSString *location = _userInfoDataSource[@"location"];
    if (location != nil && ![location isEqualToString:@""]) {

        [request setValue:location forParameter:@"location"];
    }
    
    //所在学校
    NSString *school = _userInfoDataSource[@"school"];
    if (school != nil && ![school isEqualToString:@""]) {
        
        [request setValue:school forParameter:@"school"];
    }
    
    //个性签名
    NSString *signature = _userInfoDataSource[@"signature"];
    if (signature != nil && ![signature isEqualToString:@""]) {

        [request setValue:signature forParameter:@"signature"];
    }
    
    [request asynchronous];
}

#pragma mark - 私有方法

/*!
 @abstract 向服务器请求获得个人信息
 */
- (void)userInfoRequest
{
    JSONRequest* request = [[JSONRequest alloc] initWithURLString:_JSON_URL_U_GET_BASICINFO];
    request.delegate = self;
    request.hudOn = true;
    request.hudTitle = _L(@"title_loading_01");
    [request setValue:_ACCOUNT_ID forParameter:@"userId"];
    [request asynchronous];
}

/*!
 @abstract 头像选择后，保存图片
 */
- (void)saveImage:(UIImage *)image {
    
    //压缩图片
    UIImage *newImage = [Helper resizeImage:image forStyle:PictureStyleAvart];
    NSData *imageData = [Helper compressImageData:newImage withStyle:PictureStyleAvart];
    
    //保存在数据源中
    [_userInfoDataSource setObject:imageData forKey:@"previewAvatar"];

    _avatarImageView.image = [UIImage imageWithData:imageData];
}

/*!
 @abstract 裁剪图片
 */
- (void)cropImage:(UIImage *)image
{
    //获得图片后，进行裁剪
    GKImageCropper* cropper = [[GKImageCropper alloc] init];
    cropper.delegate = self;
    cropper.image = image;
    cropper.cropSize = CGSizeMake(320, 320);
    cropper.rescaleImage = NO;
    cropper.rescaleFactor = 1.0;
    cropper.dismissAnimated = YES;
    
    [self presentModalViewController:cropper animated:YES];
}

- (void)imageCropperDidFinish:(GKImageCropper *)imageCropper withImage:(UIImage *)image {
    
    [self performSelector:@selector(saveImage:) withObject:image afterDelay:0.5];
}

- (void)fillCollage:(NSNotification *)notification
{
    Collage *collage = (Collage *)notification.object;
    if (collage != nil) {
        [_userInfoDataSource setValue:[NSString stringWithFormat:@"%@ %@",collage.region, collage.name] forKey:@"school"];
    }
    [self.tableView reloadData];
}

#pragma mark - JSONRequestDelegate

//
- (void)requestDidLoadJSON:(NSDictionary *)dict
{
    
    JMFBase* jmf = [[JMFBase alloc] initWithJSONDictionary:dict];
    
    if (jmf.status == JMStatusSucceed) {
        
        _primeDataSource = dict[@"data"];
        _userInfoDataSource = [NSMutableDictionary dictionaryWithDictionary:dict[@"data"]];
//        NSLog(@"%@",_userInfoDataSource);
        [self.tableView reloadData];
        
    }
    else {
        [Helper easyShowJMFStatus:jmf];
    }
}

//
- (void)requestFailWithNetworkUnavailabe
{
    [Helper showAlertWithTitle:nil andMessage:_L(@"title_networkunavailabe")];
}

//保存成功selector
- (void)finishRequestSuccess:(NSDictionary *)dict
{
    JMFBase* jmf = [[JMFBase alloc] initWithJSONDictionary:dict];
    
    if (jmf.status == JMStatusSucceed) {
        
        //更新更多视图
        if ([_delegate respondsToSelector:@selector(avatarViewShouldReload:)]) {
            [_delegate avatarViewShouldReload:_avatarImageView.image];
        }
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }
    else {
        [Helper easyShowJMFStatus:jmf];
    }
}

#pragma mark - UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
    
    imagePicker.delegate = self;
    //拍照模式
    if (buttonIndex == 0) {
        
        //判断摄像头是否可用
        if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
            imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        }else{
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        }
        
        [self presentModalViewController:imagePicker animated:YES];
        //访问相册模式
    }else if (buttonIndex == 1){
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.allowsEditing = NO;
        [self presentModalViewController:imagePicker animated:YES];
    }
    
}

#pragma mark - UITextField Delegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

#pragma mark - InfoPickerViewController Delegate

- (void)receivingSignature:(NSString *)signature;
{
    //保存到数据源中
    [_userInfoDataSource setObject:signature forKey:@"signature"];
    
    [self.tableView reloadData];
}

- (void)receivingName:(NSString *)name
{
    //保存到数据源中
    [_userInfoDataSource setObject:name forKey:@"realName"];
    
    [self.tableView reloadData];
}

#pragma mark - UIImagePickerController Delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image;

    [picker dismissModalViewControllerAnimated:YES];
    
    //判断picker是否是可编辑相片的，如果picker为可编辑则获取编辑后的image，否则获取原始的image
    if (picker.isEditing) {
        
        image = [info objectForKey:UIImagePickerControllerEditedImage];
    }else{
        
        image = [info objectForKey:UIImagePickerControllerOriginalImage];
    }
    
    [Helper showAllTextDialog:_L(@"title_loading_01") inSeconds:1];
    [self performSelector:@selector(cropImage:) withObject:image afterDelay:1];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissModalViewControllerAnimated:YES];
}

#pragma mark - UICustomPickerView DataSource

- (NSInteger)numberOfComponentsInUICustomPickerView:(UICustomPickerView *)customPickerView
{
    return 1;
}
- (NSInteger)customPickerView:(UICustomPickerView *)customPickerView
      numberOfRowsInComponent:(NSInteger)component
{
    return _sexArray.count;
}

#pragma mark - UICustomPickerView Delegate
- (NSString *)customPickerView:(UICustomPickerView *)customPickerView titleForRow:(NSInteger)row
                  forComponent:(NSInteger)component
{
    return _sexArray[row];
}

- (void)customPickerView:(UICustomPickerView *)customPickerView didSelectRow:(NSInteger)row
             inComponent:(NSInteger)component
{
    [_userInfoDataSource setValue:[NSString stringWithFormat:@"%d",row] forKey:@"sex"];
    
    [self.tableView reloadData];
}


- (void)customPickerViewDateChanged:(NSString *)date
{
    [_userInfoDataSource setValue:date forKey:@"birthday"];
    
    [self.tableView reloadData];
    
}

- (void)customPickerView:(UICustomPickerView *)customPickerView areaStringReceived:(NSString *)area
{
    
    [_userInfoDataSource setValue:area forKey:@"location"];
    
    [self.tableView reloadData];
}

#pragma mark - UIAlertView Delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        
        [self.navigationController popViewControllerAnimated:YES];
    }
}
@end
